<template>
	<view class="capital">
		 <u-sticky bgColor="#fff">
			<u-tabs :list="list" lineColor="#c30d23" inactiveStyle="#837c7a" 
				activeStyle="font-weight:bold" :scrollable="false"
				@change="changeTabs"
			></u-tabs>
		</u-sticky>
		
		<template v-if="tabIndex === 0">
			<view class="content">
				<view class="row flex-j-sb">
					<text class="txt">资金账号</text>
					<text>{{capitalInfo.fundAccount || ''}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">期初余额</text>
					<text>{{transfer(capitalInfo.openingBalance)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">末期余额</text>
					<text>{{transfer(capitalInfo.endingBalance)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">净值</text>
					<text>{{transfer(capitalInfo.netWorth)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">可用资金</text>
					<text>{{transfer(capitalInfo.availableBalance)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">占用资金</text>
					<text>{{transfer(capitalInfo.occupyBalance)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">预扣保证金</text>
					<text>{{transfer(capitalInfo.margin)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">浮动盈亏</text>
					<text>{{transfer(capitalInfo.none)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">今日入金</text>
					<text>{{transfer(capitalInfo.none)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">今日出金</text>
					<text>{{transfer(capitalInfo.none)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">今日损益</text>
					<text>{{transfer(capitalInfo.none)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">交易手续费</text>
					<text>{{transfer(capitalInfo.commission)}}</text>
				</view>
				<view class="row flex-j-sb">
					<text class="txt">状态</text>
					<text class="status">{{capitalInfo.stateStr}}</text>
				</view>
			</view>
		</template>
		
		<template v-if="tabIndex === 1">
			<view class="content">
				<view class="row flex-j-sb">
					<text class="txt">资金类型</text>
					<view class="picker-box">
						<picker mode="selector" @change="pickerChange">
							<view class="flex-j-sb">
								<view class="picker-type">全部</view>
								<u-icon name="arrow-right" size="18"></u-icon>
							</view>
						</picker>
					</view>
				</view>
			</view>
			
			<view class="content list" v-if="dataList.length">
				<view class="item flex-a-c">
					<text class="item-time">时间</text>
					<text class="item-type">操作类型</text>
					<text class="item-amount">金额</text>
				</view>
				<view class="item flex-a-c" v-for="(item,index) in dataList" :key="item.id">
					<view class="item-time">
						<view>2023-12-24</view>
						<text class="small">12:00:20</text>
					</view>
					<text class="item-type">交易解占用</text>
					<text class="item-amount">{{item.usePrice}}</text>
				</view>
			</view>
			<view class="none" v-else>暂无数据</view>
		</template>
		
		<template  v-if="tabIndex === 2">
			<view class="none">暂无数据</view>
		</template>
	</view>
</template>

<script>
	import { getUserCapital,getUserBill } from '@/api/home.js'
	import {mapGetters} from 'vuex'
	export default {
		data() {
			return {
				_isLoading:false,
				tabIndex:0,
				list:[
					{name:'资金信息'},
					{name:'资金流水'},
					{name:'结算单'},
					
				],
				capitalInfo:{},
				dataList:[],
				page:1,
				size:10
			}
		},
		onLoad() {
			this.getData()
		},
		onReachBottom() {
			if(this._isLoading) return
			if((this.page * this.size) > this.dataList.length) return uni.$showToast('暂无更多数据')
			this.page++
			this.getBill()
		},
		computed:{
			...mapGetters(['userInfo'])
		},
		methods:{
			async getData(){ //  
				const res = await getUserCapital({
					userName:this.userInfo.userName,
				})
				// console.log(res);
				if(res.rows) {
					this.capitalInfo = res.rows[0]
				}
			},
			async getBill(){ //资金流水
				this._isLoading = true
				const res = await getUserBill({
					fundAccount:this.capitalInfo.fundAccount,
					pageSize:this.size,
					pageNum:this.page,
				})
				this._isLoading = false
				// console.log(res);
				if(res.rows) {
					this.dataList = this.dataList.concat(res.rows)
				}
			},
			transfer(num){
				return num?Number(num).toFixed(2):'0.00'
			},
			changeTabs(e){
				this.tabIndex = e.index
				if(!this.dataList.length) {
					this.getBill()
				}
			},
			onNavigationBarButtonTap(e){ // 点击更多
				console.log(e);
			}
		}
	}
</script>
<style lang="scss" scoped>
	.capital {
		padding-bottom: 10rpx;
	}
	.content {
		background-color: white;
		margin: 10rpx;
		padding:0px 20rpx;
		.row {
			padding: 20rpx 0px;
			color: gray;
			text-align: right;
			+.row {
				border-top: 1rpx solid #eee;
			}
			.txt {
				flex-shrink: 0;
				margin-right: 20rpx;
				color: black;
			}
			.ipt {
				flex: 1;
			}
			.red {
				color: #E20000;
			}
			.picker-box {
				flex: 1;
				.picker-type {
					flex: 1;
					text-align: center;
				}
			}
		}
		
		.status {
			// color: #1AA034;
		}
	}
	
	.list {
		font-size: 28rpx;
		.item {
			padding: 20rpx 0px;
			text-align: center;
			+.item {
				border-top: 1rpx solid #eee;
			}
			&:first-child {
				color: gray;
				font-size: 26rpx;
			}
			.item-time {
				width: 30%;
				.small {
					color: gray;
					font-size: 24rpx;
				}
			}
			.item-type {
				width: 45%;
			}
			.item-amount {
				width: 25%;
				text-align: right;
			}
		}	
	}
	
	.none {
		font-size: 30rpx;
		margin-top: 100rpx;
		text-align: center;
	}
</style>